package logic

import (
	"context"
	"fmt"
	"shop_srv/internal/svc"
	"shop_srv/model/mysql"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *shop.ShopAddRequest) (*shop.ShopAddResponse, error) {
	// todo: add your logic here and delete this line
	s := mysql.Shop{
		Title:  in.Title,
		Cover:  in.Cover,
		Status: in.Status,
		Stock:  int(in.Stock),
		Price:  float64(in.Price),
	}
	err := mysql.DB.Create(&s).Error
	if err != nil {
		fmt.Println("添加失败")
	}
	return &shop.ShopAddResponse{
		ShopId: int64(s.ID),
	}, nil
}
